package com.bf.electroplating.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bf.electroplating.pojo.dto.IdDTO;
import com.bf.electroplating.pojo.dto.workshop.ComWorkshopDTO;
import com.bf.electroplating.pojo.entity.ComWorkshop;
import com.bf.electroplating.pojo.vo.ResultVO;
import com.bf.electroplating.pojo.vo.workshop.ComWorkshopVO;
import com.bf.electroplating.service.ComWorkshopService;
import com.bf.electroplating.util.idempotent.Idempotent;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/workshop")
@Tag(name = "车间管理", description = "车间信息管理")
public class ComWorkshopController {

    @Resource
    private ComWorkshopService comWorkshopService;

    @PostMapping("/list")
    @Operation(summary = "获取车间列表", description = "分页获取车间列表信息")
    public ResultVO<Page<ComWorkshopVO>> getWorkshopList(@RequestBody ComWorkshopDTO dto) {
        return ResultVO.ok(comWorkshopService.getWorkshopList(dto));
    }

    @PostMapping("/getWorkshopById")
    @Operation(summary = "获取车间详情", description = "根据ID获取车间详细信息")
    public ResultVO<ComWorkshopVO> getWorkshopById(@RequestBody IdDTO id) {
        return ResultVO.ok(comWorkshopService.getWorkshopById(id.getId()));
    }

    @Idempotent
    @PostMapping("/saveWorkshop")
    @Operation(summary = "新增车间", description = "新增车间信息")
    public ResultVO<Boolean> saveWorkshop(@RequestBody ComWorkshopVO vo) {
        return ResultVO.ok(comWorkshopService.saveWorkshop(vo), "保存成功");
    }

    @Idempotent
    @PostMapping("/updateWorkshop")
    @Operation(summary = "修改车间", description = "修改车间信息")
    public ResultVO<Boolean> updateWorkshop(@RequestBody ComWorkshopVO vo) {
        return ResultVO.ok(comWorkshopService.updateWorkshop(vo), "保存成功");
    }

    @PostMapping("/deleteWorkshop")
    @Operation(summary = "删除车间", description = "根据ID删除车间信息")
    public ResultVO<Boolean> deleteWorkshop(@RequestBody IdDTO id) {
        return ResultVO.ok(comWorkshopService.deleteWorkshop(id.getId()), "删除成功");
    }

    @PostMapping("/batch")
    @Operation(summary = "批量删除车间", description = "批量删除车间信息")
    public ResultVO<Boolean> batchDeleteWorkshop(@RequestBody List<String> ids) {
        return ResultVO.ok(comWorkshopService.batchDeleteWorkshop(ids), "删除成功");
    }

    @PostMapping("/changelogList")
    @Operation(summary = "获取变更记录", description = "获取变更记录")
    public ResultVO < List < ComWorkshopVO > > changelogList(@RequestBody IdDTO id) {
        return ResultVO.ok(comWorkshopService.changelogList(id.getId()));
    }

    @GetMapping("/getDropdowMenu")
    @Operation(summary = "获取车间下拉框", description = "获取车间下拉框")
    public ResultVO<List<ComWorkshop>> getDropdowMenu(@RequestParam(value = "companyId",required = false) String companyId) {
        return ResultVO.ok(comWorkshopService.getDropdowMenu(companyId));
    }
} 